package com.mijie.homi.test;

import java.util.HashMap;
import java.util.Map;

public class WordStat {

	private int type;
	private int freq;
	private Map<Integer,Integer> typeIntersectCounter = new HashMap<Integer,Integer>(10);
	
	public WordStat(int type){
		this.type = type;
	}
	
	public int freq(){
		return freq;
	}
	
	public void increFreq(){
		freq++;
	}
	
	public int type(){
		return type;
	}
	
	public void increTypeIntersect(int type){
		Integer count = typeIntersectCounter.get(type);
		if(count==null) count=0;
		typeIntersectCounter.put(type, count+1);
	}
	
	public int intersectCount(int type){
		Integer count =  typeIntersectCounter.get(type);
		return count==null?0:count;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for(Integer type : typeIntersectCounter.keySet()){
			sb.append(type+"=>"+typeIntersectCounter.get(type)).append(",");
		}
		return "WordStat [type=" + type + ", freq=" + freq
				+ ", "+sb.toString()+" ]";
	}
	
	
}
